package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.pojo.user.ChargeUser;
import com.zhentao.model.pojo.user.record.ChargeUserIncome;
import com.zhentao.service.ChargeUserIncomeService;
import com.zhentao.mapper.ChargeUserIncomeMapper;
import com.zhentao.user.ChargeUserThreadUtils;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.zhentao.model.common.enums.AppHttpCodeEnum.NEED_LOGIN;

/**
* @author 31919
* @description 针对表【charge_user_income】的数据库操作Service实现
* @createDate 2024-12-22 20:31:35
*/
@Service
public class ChargeUserIncomeServiceImpl extends ServiceImpl<ChargeUserIncomeMapper, ChargeUserIncome>
    implements ChargeUserIncomeService{

    /**
     * @description  我的收益
     * @author 大毅
     * @return ResponseResult
     */
    @Override
    public ResponseResult getBalanceChangeList() {
        //获取登录用户
        ChargeUser user = ChargeUserThreadUtils.getChargeUserThreadLocal();
        if (StringUtils.checkValNull(user)){
            return ResponseResult.errorResult(NEED_LOGIN);
        }
        LambdaQueryWrapper<ChargeUserIncome> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ChargeUserIncome::getUserId, user.getId());
        List<ChargeUserIncome> list = list(wrapper);
        return ResponseResult.okResult(list);
    }
}




